package com.sdy.healthcode.biz.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.sdy.common.model.BizException;
import com.sdy.healthcode.biz.dto.DoctorManDTO;
import com.sdy.healthcode.biz.dto.DoctorManagerDTO;
import com.sdy.healthcode.biz.mapper.ExpertsInformationMapper;
import com.sdy.healthcode.biz.model.ExpertsInformation;
import com.sdy.healthcode.biz.service.ExpertsInformationService;
import com.sdy.mvc.service.impl.BaseServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.Set;


/**
 * <p>
 * 专家简介、照片统计表 服务实现类
 * </p>
 *
 * @author zzq
 * @since 2020-03-04
 */
@Slf4j
@Service
public class ExpertsInformationServiceImpl extends BaseServiceImpl<ExpertsInformation> implements ExpertsInformationService {
    @Autowired
    private ExpertsInformationMapper expertsInformationMapper;

    @Override
    public Integer deldteByDocId(Integer id) {
        return expertsInformationMapper.deleteById(id);
    }

    @Override
    public void updateDocMess(ExpertsInformation expertsInformation) throws BizException {
        lambdaUpdate().eq(ExpertsInformation::getId, expertsInformation.getId())
                .set(ExpertsInformation::getName, expertsInformation.getName())
                .set(ExpertsInformation::getPhoneNumber, expertsInformation.getPhoneNumber())
                .set(ExpertsInformation::getDepartmentId, expertsInformation.getDepartmentId())
                .set(ExpertsInformation::getProfessionalTitle, expertsInformation.getProfessionalTitle())
                .set(ExpertsInformation::getPhotoPath, expertsInformation.getPhotoPath())
                .set(ExpertsInformation::getIntroduction, expertsInformation.getIntroduction())
                .set(ExpertsInformation::getUpdateTime, new Date())
                .set(ExpertsInformation::getSuspendService, expertsInformation.getSuspendService())
                .set(ExpertsInformation::getVisitPrice, expertsInformation.getVisitPrice())
                .set(ExpertsInformation::getReplaceDoctor, expertsInformation.getReplaceDoctor())
                .update();
    }

    @Override
    public Boolean saveDoctorMess(ExpertsInformation expertsInformation) throws BizException {
        return save(expertsInformation);
    }

    @Override
    public List<DoctorManDTO> queryParmDoc(String name, Integer suspendService, Page page) {
        return expertsInformationMapper.selectParamDoctor(name, suspendService, page);
    }

    @Override
    public IPage<DoctorManagerDTO.Doctor> pageDoctorManage(Page<DoctorManagerDTO.Doctor> page, Map<String, Object> map) {
        return expertsInformationMapper.pageDoctorManage(page, map);
    }

    @Override
    public void batchDoctorSettingState(Map<Integer, Set<Integer>> batchStateSettings) {
        batchStateSettings.forEach((suspendService, doctorIdList) -> {
            if (suspendService != null && doctorIdList != null && !doctorIdList.isEmpty()) {
                lambdaUpdate()
                        .inOrThrow(ExpertsInformation::getId, doctorIdList)
                        .set(ExpertsInformation::getSuspendService, suspendService)
                        .update();
            }
        });
    }
}
